function PlotPath(aircraft,weather,target,settings,fig);
%*=+--+=#=+--      UAS Severe Weather Simulation Softeware        --+=#=+--+=#*%
%          Copyright (C) 2013 Regents of the University of Colorado.           %
%                             All Rights Reserved.                             %
%                                                                              %
%    This program is free software: you can redistribute it and/or modify      %
%    it under the terms of the GNU General Public License version 2 as         %
%    published by the Free Software Foundation.                                %
%                                                                              %
%    This program is distributed in the hope that it will be useful,           %
%    but WITHOUT ANY WARRANTY; without even the implied warranty of            %
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             %
%    GNU General Public License for more details.                              %
%                                                                              %
%    You should have received a copy of the GNU General Public License         %
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.     %
%                                                                              %
%           Jack Elston                                                        %
%           elstonj@colorado.edu                                               %
%                                                                              %
%*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*%

movieframe = 1;
figure(fig); clf;
%plot(weather,settings.sim.tf,500,'rain',fig)
%axis([2.75*10^4 7*10^4 3.75*10^4 8*10^4])
%hold on 
%plot(aircraft,fig,'track')          
ua_log = aircraft.log;

colors = [   1   0   0;
             1 0.5   0;
             1   1   0;
           0.5   1   0;
             0   1   0;
             0   1 0.5;
             0   1   1;
             0   0.5 1;
             0   0   1 ];

frame = weather.frame;
ref = target;

for time = settings.sim.t0:1:settings.sim.tf

  %plot(ua_log.position(ti:tf,1),ua_log.position(ti:tf,2),'color',colors(time/60,:));
  hold off;
  plot(weather,time,500,'rain wind il',fig)
  colormap(gray);
  hold on;

  %---controller path---%
  if mod(time,60)== 0
    fname = sprintf('bin/[cost_map]_%s_%ds_%dms.mat',weather.source,time-mod(time,60),aircraft.velocity);

    if exist(fname) == 2
      load(fname);
    else
      return;
    end;

    [px,py] = gradient(cost_map);
    temp = -px;
    px = -py;
    py = temp;
    px(isnan(px)) = .5;
    px(find(px == Inf)) = .5;
    px(find(px == -Inf)) = -.5;
    py(isnan(py)) = .5;
    py(find(py == Inf)) = .5;
    py(find(py == -Inf)) = -.5;

    if time == settings.sim.t0
      pos = ua_log.position(2,1:2);
    else
      pos = ua_log.position(floor((time-settings.sim.t0)/settings.sim.ts)+1,1:2);
    end
    points=pos;
    plot(target.x,target.y,'og','MarkerFaceColor',[0 1 0]);
    while norm(pos - [target.x,target.y]) > 800

      vector = weather(time, [pos 500]);
      u = vector(1);
      v = vector(2);

      p = floor((pos-[(time-settings.sim.t0)*frame.u,(time-settings.sim.t0)*frame.v])./500)+1;
      pos = pos + 1000*[px(p(1),p(2)),py(p(1),p(2))] + 2*[u,v]; 
      points = [points; pos];
    end
  end
  %---controller path---%

  %---ua path---%
  plot(points(:,1),points(:,2),'-y','LineWidth',3);
  plot(ua_log.position(2:floor((time-settings.sim.t0)/settings.sim.ts)+1,1),ua_log.position(2:floor((time-settings.sim.t0)/settings.sim.ts)+1,2),'-r','LineWidth',3);
  plot(ua_log.position(2,1),ua_log.position(2,2),'^k','MarkerFaceColor',[1 0 0],'LineWidth',2,'MarkerSize',14);
  plot(ua_log.position(1:60:floor((time-settings.sim.t0)/settings.sim.ts)+1,1),ua_log.position(1:60:floor((time-settings.sim.t0)/settings.sim.ts)+1,2),'^k','MarkerFaceColor',[1 0 0],'LineWidth',2,'MarkerSize',14);
  %---ua path---%

  plot(target.x,target.y,'og','MarkerFaceColor',[0 1 0],'LineWidth',2,'MarkerSize',8);
  %target=FindTarget(settings,weather,target,time,500);
  axis([1.8 4 1 3.2]*10^4);

  target.x = ref.x + 1.3*(time-settings.sim.t0);
  target.y = ref.y - 8.1*(time-settings.sim.t0);
  pause(0.10);
  M(movieframe) = getframe;
  movieframe=movieframe+1;
end
hold off;

movie2avi(M,'path.avi');
